package com.moonciki.artadmin.web.controller.student;

import com.moonciki.artadmin.common.annotation.Log;
import com.moonciki.artadmin.common.enums.BusinessType;
import com.moonciki.artadmin.core.base.BaseController;
import com.moonciki.artadmin.core.model.FileWrapper;
import com.moonciki.artadmin.core.model.PageData;
import com.moonciki.artadmin.core.model.PageParameter;
import com.moonciki.artadmin.core.model.WebResult;
import com.moonciki.artadmin.web.mybatis.entity.fuzhu.FzStudent;
import com.moonciki.artadmin.web.service.student.IFzStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学生Controller
 *
 * @author ruoyi
 * @date 2022-02-16
 */
@Api(tags = "学生接口")
@RestController
@RequestMapping("/fuzhu/student")
public class FzStudentController extends BaseController {

    @Autowired
    private IFzStudentService fzStudentService;

    @ApiOperation(value = "查询学生列表")
    @PreAuthorize("@ss.hasPermi('fuzhu:student:list')")
    @GetMapping("/list")
    public WebResult<PageData<FzStudent>> list(PageParameter pageParameter, FzStudent fzStudent) {
        PageData<FzStudent> pageData = fzStudentService.getPageList(pageParameter, fzStudent);
        WebResult<PageData<FzStudent>> result = WebResult.successResponse(pageData);
        return result;
    }

    @ApiOperation(value = "导出学生列表")
    @PreAuthorize("@ss.hasPermi('fuzhu:student:export')")
    @Log(title = "学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FzStudent fzStudent) {
        FileWrapper fileWrapper = fzStudentService.export(fzStudent);

        super.responseFile(response, fileWrapper);
    }

    @ApiOperation(value = "获取学生详细信息")
    @PreAuthorize("@ss.hasPermi('fuzhu:student:detail')")
    @GetMapping(value = "/detail")
    public WebResult<FzStudent> detail(Long id) {
        FzStudent fzStudent = fzStudentService.getById(id);
        return WebResult.successResponse(fzStudent);
    }

    @ApiOperation(value = "新增学生")
    @PreAuthorize("@ss.hasPermi('fuzhu:student:add')")
    @Log(title = "学生", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public WebResult<FzStudent> add(@RequestBody FzStudent fzStudent) {
        FzStudent insert = fzStudentService.insertFzStudent(fzStudent);
        return WebResult.successResponse(insert);
    }

    @ApiOperation(value = "修改学生")
    @PreAuthorize("@ss.hasPermi('fuzhu:student:edit')")
    @Log(title = "学生", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public WebResult<Integer> edit(@RequestBody FzStudent fzStudent) {
        int edit = fzStudentService.updateFzStudent(fzStudent);
        return WebResult.successResponse(edit);
    }

    @ApiOperation(value = "删除学生")
    @PreAuthorize("@ss.hasPermi('fuzhu:student:remove')")
    @Log(title = "学生", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete")
    public WebResult<Integer> remove(@RequestBody List<Long> idList) {
        int i = fzStudentService.deleteByIds(idList);
        return WebResult.successResponse(i);
    }

}
